package com.sharer.last.base.exception;

import com.sharer.last.base.interfaces.BaseExceptionCode;
import com.sharer.last.base.enums.BusinessExceptionCode;
import com.sharer.last.base.enums.ExceptionPrefixParamEnum;

/**
 * 业务异常
 *
 * @ClassName BusinessException
 * @Author WangJin
 * @Date 2023/05/22/11:26
 * @Description
 * @Version 1.0
 */
public class BusinessException extends RuntimeException {
    private int code;

    private String msg;

    private BaseExceptionCode exceptionCode;

    public BusinessException(BaseExceptionCode businessExceptionCode) {
        super(businessExceptionCode.getMsg());
        this.exceptionCode = businessExceptionCode;
        this.code = businessExceptionCode.getCode();
        this.msg = businessExceptionCode.getMsg();
    }

    public BusinessException(BaseExceptionCode businessExceptionCode, ExceptionPrefixParamEnum prefix) {
        super(prefix.getText() + businessExceptionCode.getMsg());
        this.exceptionCode = businessExceptionCode;
        this.code = businessExceptionCode.getCode();
        this.msg = prefix.getText() + businessExceptionCode.getMsg();
    }

    public BusinessException(BaseExceptionCode businessExceptionCode, Throwable cause) {
        super(businessExceptionCode.getMsg(), cause);
        this.exceptionCode = businessExceptionCode;
    }

    public BusinessException(BaseExceptionCode businessExceptionCode, ExceptionPrefixParamEnum prefix, Throwable cause) {
        super(prefix.getText() + businessExceptionCode.getMsg(), cause);
        this.exceptionCode = businessExceptionCode;
        this.code = businessExceptionCode.getCode();
        this.msg = prefix.getText() + businessExceptionCode.getMsg();
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public BaseExceptionCode getExceptionCode() {
        return exceptionCode;
    }
}
